﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WriteBugs.Pages
{
    internal class ConsoleWiiteEventArgs : EventArgs
    {
        public string? value { get; set; }
    }

    internal delegate void ConsoleWiiteEventHandler(ConsoleWiiteEventArgs args);

    internal class DebugConsloeWriter : TextWriter
    {
        public event ConsoleWiiteEventHandler? WriteMessage;

        public DebugConsloeWriter()
        {
        }

        public override Encoding Encoding
        {
            get { return Encoding.UTF8; }
        }

        public override void WriteLine()
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = "\r\n", });
        }

        public override void WriteLine(bool value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString() + "\r\n", });
        }

        public override void WriteLine(char value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString() + "\r\n", });
        }

        public override void WriteLine(string? value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value + "\r\n", });
        }

        public override void WriteLine(int value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString() + "\r\n", });
        }

        public override void WriteLine(long value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString() + "\r\n", });
        }

        public override void WriteLine(float value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString() + "\r\n", });
        }
        public override void WriteLine(double value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString() + "\r\n", });
        }

        public override void WriteLine(object? value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value?.ToString() + "\r\n", });
        }

        //

        public override void Write(bool value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString(), });
        }

        public override void Write(char value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString(), });
        }

        public override void Write(string? value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value, });
        }

        public override void Write(int value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString(), });
        }

        public override void Write(long value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString(), });
        }

        public override void Write(float value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString(), });
        }
        public override void Write(double value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value.ToString(), });
        }

        public override void Write(object? value)
        {
            WriteMessage?.Invoke(new ConsoleWiiteEventArgs { value = value?.ToString(), });
        }
    }
}
